package com.mxt.controller;

import com.mxt.biz.CustomerBiz;
import com.mxt.biz.MyTypeBiz;
import com.mxt.entity.Customer;
import com.mxt.entity.MyType;
import com.mxt.entity.QueryCustomer;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author mxt
 * @date 2021/11/19 10:21
 */
@Controller
@RequestMapping("crm")
public class CrmController {
    @Resource
    private MyTypeBiz myTypeBiz;
    @Resource
    private CustomerBiz customerBiz;

    @RequestMapping(value = "update",method = RequestMethod.GET)
    @ResponseBody
    public  Customer update( int id){
        Customer c=customerBiz.queryByID(id);
        return  c;
    }
    @RequestMapping(value = "update",method = RequestMethod.POST)
    @ResponseBody
    public  boolean update(Customer customer){
        return  customerBiz.update(customer);
    }
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    @ResponseBody
    public  boolean delete(int uid){
        return  customerBiz.delete(uid);
    }



    @RequestMapping("index")
    public  String crm(QueryCustomer qc, Model model){
        List<MyType> industryType=myTypeBiz.queryByType("所属行业");
        List<MyType> levelType=myTypeBiz.queryByType("客户级别");
        //List<Customer> customerlist=customerBiz.queryAll();
        List<Customer> customerlist=customerBiz.queryByQueryCustomer(qc);
        model.addAttribute("industryType",industryType);
        model.addAttribute("levelType",levelType);
        model.addAttribute("customerlist",customerlist);
        model.addAttribute("qc",qc);
        return "crm";
    }
    @RequestMapping("{page}/aaaa/{hangye}/hahaha/{jibie}/{name}/index")
    public String crm(@PathVariable int page,@PathVariable int hangye,@PathVariable int jibie,@PathVariable String name,Model model){
        QueryCustomer qc=new QueryCustomer();
        qc.setPage(page);
        if(!name.equals("!")){
            qc.setName(name);
        }
        qc.setHangye(hangye);
        qc.setJibie(jibie);
        return  crm(qc,model);
    }
}
